#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author:    thepoy
# @Email:     thepoy@163.com
# @File Name: postgresql_psycopg_sync.py
# @Created:   2021-12-27 17:09:31
# @Modified:  2021-12-28 15:15:10

import psycopg

from psycopg import Connection


def main():
    conn: Connection = psycopg.connect(
        # 如果在 windows 中连接太慢，可以尝试添加 gssencmode=disable 属性
        "host=xxxx user=xxxx password=xxxx dbname=xxxx sslmode=disable"
    )
    cur = conn.cursor()
    cur.execute("SELECT id FROM items LIMIT 1;")
    row = cur.fetchone()
    if not row:
        raise Exception("没有结果")
    print(f"result: id={row[0]}")


if __name__ == "__main__":
    main()
